package com.wm.blog_admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wm.blog_admin.controller.base.AdminBaseController;
import com.wm.blog_admin.query.TTagQuery;
import com.wm.blog_admin.service.TTagService;
import com.wm.blog_common.bean.QueryPage;
import com.wm.blog_common.domain.TTagDO;
import com.wm.blog_common.entity.TTag;
import com.wm.blog_common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 标签表 前端控制器
 * </p>
 *
 * @author wm_yu
 * @since 2020-03-24
 */
@Slf4j
@RestController
@RequestMapping("/blog/tag")
public class TTagController extends AdminBaseController {

    @Autowired
    private TTagService tTagService;

    /**
     * 根据ID查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<TTagDO> get(@PathVariable Long id) {
        return tTagService.selectById(id);
    }

    /**
     * 根据ID删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result<Boolean> delete(@PathVariable Long id){
        return tTagService.deleteById(id);
    }

    /**
     * 添加
     * @param tTag
     * @return
     */
    @PostMapping
    public Result insert(@RequestBody TTag tTag){
        return tTagService.insert(tTag);
    }

    /**
     * 修改
     * @param tTag
     * @return
     */
    @PutMapping
    public Result update(@RequestBody TTag tTag){
        return tTagService.update(tTag);
    }

    /**
     * 分页查询
     * @param current   查询页
     * @param size   每页显示条数
     * @param query 查询参数
     * @return
     */
    @GetMapping("/page")
    public Result<Page<TTagDO>> page(Integer current, Integer size, TTagQuery query){
        return tTagService.page(new QueryPage(current,size),query);
    }


    /**
     * Excel导出
     * @param query
     */
    @GetMapping("/exportTag")
    public void export(TTagQuery query, HttpServletResponse response){
         tTagService.export(query,response);
    }


    /**
     * 详情查询
     */
    @GetMapping("/getDetail")
    public Result getDetail(Long id){
        return tTagService.getDetail(id);
    }

}
